<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script src="./js/subscribe.js"></script>

  <script>
    function fn1() {
      console.log(1);
    }
    function fn2(x, y) {
      console.log(2, x, y);
      // 第一次执行fn2, 就把 fn1/fn2 从事件池移除
      sub.$off('marry', fn1);
      sub.$off('marry', fn2);
      /* 
        第一次只执行到了1， 2 数组塌陷问题
       */
    }
    function fn3() {
      console.log(3);
    }
    function fn4() {
      console.log(4);
    }
    function fn5() {
      console.log(5);
    }

    let sub = subscribe();
    sub.$on('marry', fn1);
    sub.$on('marry', fn2);
    sub.$on('marry', fn3);
    sub.$on('marry', fn4);
    sub.$on('marry', fn5);

    /* setTimeout(() => {
      sub.$emit('marry', 10, 20);
    }, 2000); */

    document.onclick = function() {
      sub.$emit('marry', 10, 20);
    }
  </script>
</body>
</html>